package maths

func RoundUpPowerOfTwo(n uint64) uint64 {
	if n <= 0 {
		return 1
	}
	// Decrease n by 1 to handle cases where n is already a power of two
	n--
	// Set all bits to the right of the leftmost set bit
	n |= n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	n |= n >> 32 // This step is necessary for 64-bit integers
	// Add 1 to get the next power of two
	return n + 1
}
